package com.example.memolaga.cards;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import com.example.memolaga.Functions;
import com.example.memolaga.R;
import com.example.memolaga.Constants;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
import android.content.Context;


public class CardAdd extends Activity {
	
	private String sKey;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle bundle = this.getIntent().getExtras();
		if (bundle!=null)
			this.sKey = bundle.getString(Constants.getKeyString());
		else
			Log.i("CredAdd","sKey null");
        setContentView(R.layout.card_add);
		Button btnSave = (Button) findViewById(R.id.btnCardSave);
		btnSave.setOnClickListener(saveCardListener);
	}
	
	 private OnClickListener saveCardListener = new OnClickListener()
	 {

		@Override
		public void onClick(View arg0) {
			String name = ((EditText) findViewById(R.id.editCardName)).getText().toString();
			String number = ((EditText) findViewById(R.id.editCardNumber)).getText().toString();
			String pin = ((EditText) findViewById(R.id.editCardPin)).getText().toString();
			String cvv = ((EditText) findViewById(R.id.editCardCVV)).getText().toString();
			String phone = ((EditText) findViewById(R.id.editCardPhone)).getText().toString();
			String circuits = ((EditText) findViewById(R.id.editCardCircuits)).getText().toString();
            String expiry = ((EditText) findViewById(R.id.editCardExpiry)).getText().toString();
            String balance = ((EditText) findViewById(R.id.editCardBalance)).getText().toString();;
            String holder = ((EditText) findViewById(R.id.editCardHolder)).getText().toString();;
            String billAddress = ((EditText) findViewById(R.id.editCardBillAddress)).getText().toString();;
			String bank = ((EditText) findViewById(R.id.editCardBank)).getText().toString();
			String website = ((EditText) findViewById(R.id.editCardWebsite)).getText().toString();
			String note = ((EditText) findViewById(R.id.editCardNote)).getText().toString();
            CardsManager.getInstance().cardAdd(name, number, pin, cvv, phone, circuits, expiry, balance, holder, billAddress, bank,  website, note, sKey);
            Functions.showLongToast(getBaseContext(),getString(R.string.strOKCreateFile));
            setResult(Constants.getResultEdit());
            finish();
		}
		 
	 };
	 

	/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_card_add, menu);
		return true;
	}
*/
}
